package com.cooldatasoft.support;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

import com.cooldatasoft.domain.model.User;


/**
 * @author stupi20
 */
@SuppressWarnings("deprecation")
public class TaskManagerUserDetails implements UserDetails {
	private static final long serialVersionUID = -4071371677752405277L;
	private Logger logger = Logger.getLogger(TaskManagerUserDetails.class);
	private User user;

	private boolean accountNonExpired = true;
	private boolean accountNonLocked = true;
	private boolean credentialsNonExpired = true;

	public TaskManagerUserDetails(User user) {
		this.user = user;
	}

	public User getCurrentUser() {
		return user;
	}

	public Collection<GrantedAuthority> getAuthorities() {
		logger.debug("getAuthorities()");

		String role = "ROLE_USER";
		List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
		
		if(role != null) {
			grantedAuthorities.add(new GrantedAuthorityImpl(role));
		}

		return grantedAuthorities;

	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getEmail();
	}


	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}

	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}

	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}
